 <template>
    <div class="container">
      <van-nav-bar
    title="登陆页面"

  />
      <van-form @submit="onSubmit">
    <van-field
      v-model="username"
      name="username"

      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="password"

      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
    <div style="margin: 16px;">
      <van-button  block type="info" native-type="submit">提交</van-button>
    </div>
  </van-form>
<router-link to="/registred" class="link">没有账号，立即注册</router-link>

    </div>
  </template>

  <script>

  import { login } from '@/api/user'
  import { setToken } from '@/utils/stronage';
  export default {
  name:'LoginIndex',
  data() {
      return {
        username: '',
        password: '',
      };
    },

    methods: {
     async onSubmit(values) {
      const res=  await login(values)
      console.log(res)
     if(res.data.status===200){
      setToken(res.data.body.token)
      this.$toast('登录成功')
      setTimeout( ()=> {
        this.$router.push('/index')
      }, 1000)
     }
      },
    },

  }
  </script>

 <style scoped lang="less">
  body{
    height: 100%;
    background-color: #f8f8f8;
  }
  .van-form{
    margin-top: 50%;
  }
  .link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  // float: right;
  margin-left: 35%;
}
  </style>
